﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Infragistics.Windows.Ribbon;
using PTExpress.DataAccess;

namespace PTExpress.Views
{
    /// <summary>
    /// Interaction logic for frmMain.xaml
    /// </summary>
    public partial class frmMain : XamRibbonWindow
    {
        UserControl content = new UserControl();
        public delegate void EventLogOut();
        private event EventLogOut LogOut;

        #region 'Dependency Properties'
        public string UserName
        {
            get { return (string)GetValue(UserNameProperty); }
            set { SetValue(UserNameProperty, value); }
        }
        public string ServerName
        {
            get { return (string)GetValue(ServerNameProperty); }
            set { SetValue(ServerNameProperty, value); }
        }
        public string DataName
        {
            get { return (string)GetValue(DataNameProperty); }
            set { SetValue(DataNameProperty, value); }
        }

        public bool UnRegisted
        {
            get { return (bool)GetValue(UnRegistedProperty); }
            set { SetValue(UnRegistedProperty, value); }
        }

        // Using a DependencyProperty as the backing store for UnRegisted.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty UnRegistedProperty =
            DependencyProperty.Register("UnRegisted", typeof(bool), typeof(frmMain), new UIPropertyMetadata(true));
        public static readonly DependencyProperty UserNameProperty =
            DependencyProperty.Register("UserName", typeof(string), typeof(frmMain), new UIPropertyMetadata(""));
        public static readonly DependencyProperty ServerNameProperty =
            DependencyProperty.Register("ServerName", typeof(string), typeof(frmMain), new UIPropertyMetadata(""));
        public static readonly DependencyProperty DataNameProperty =
            DependencyProperty.Register("DataName", typeof(string), typeof(frmMain), new UIPropertyMetadata(""));
        #endregion

        static public string _UserName = string.Empty;

        public frmMain()
        {
            InitializeComponent();
            LogOut += new EventLogOut(frmMain_LogOut);
            StatusBar.EventLogOut = LogOut;
        }

        //Đăng nhập
        private bool Login()
        {
            frmLogin frm = new frmLogin(true);
            frm.ShowDialog();
            if (frm.close)
                return false;

            //_UserName = UserName;
            _UserName = frm.username;
            ServerName = frm.ServerName;
            DataName = frm.DatabaseName;
            App.UserName = frm.username;
            App.ServerName = frm.ServerName;
            App.DataName = frm.DatabaseName;
            //LanguageLib.IsRegisted = !UnRegisted;
            return true;
        }

        //Đăng xuất
        private void frmMain_LogOut()
        {
            //UserAccess.RememberLogin(false); 
            this.Hide();
            if (!Login())
                this.Close();
            else
                this.Show();
        }

        private void btnSoDoPhong_Click(object sender, RoutedEventArgs e)
        {
            /*
            if (content.ToString() == "QLKS.Views.ucSoDoPhong")
                return;
            content = new ucSoDoPhong();
            mainContent.Children.Clear();
            mainContent.Children.Add(content);
            Reload_Language();
            */
        }

        private void btnDmPhong_Click(object sender, RoutedEventArgs e)
        {
            /*
            if (content.ToString() == "QLKS.Views.ucDmPhong")
                return;
            content = new ucDmPhong();
            mainContent.Children.Clear();
            mainContent.Children.Add(content);
            Reload_Language();
             * */
        }

        //Load form
        private void FrmMain_Loaded(object sender, RoutedEventArgs e)
        {
            UnRegisted = App.UnRegisted;
            this.UserName = App.UserName;
            this.DataName = App.DataName;
            this.ServerName = App.ServerName;
            btnSoDoPhong_Click(null, null);
        }

        //Báo cáo
        private void btnBCDoanhThuTheoLoaiPhong_Click(object sender, RoutedEventArgs e)
        {
            /*
            frmDKLocBCDoanhThuTheoLoaiPhong frm = new frmDKLocBCDoanhThuTheoLoaiPhong();
            frm.ShowDialog();
            if (!frm.flag)
                return;
            (new frmBCDoanhThuTheoLoaiPhong(frm.nam, frm.ky)).ShowDialog();
             * */
        }

        /*
        private void SetTitle()
        {
            if (content is Views.ucDmKhachHang)
                ((Views.ucDmKhachHang)content).SetTitle();
            if (content is Views.ucDmLoaiPhong)
                ((Views.ucDmLoaiPhong)content).SetTitle();
            if (content is Views.ucDmNguoiDung)
                ((Views.ucDmNguoiDung)content).SetTitle();
            if (content is Views.ucDmNhanVien)
                ((Views.ucDmNhanVien)content).SetTitle();
            if (content is Views.ucDmPhong)
                ((Views.ucDmPhong)content).SetTitle();
            if (content is Views.ucDmTienTe)
                ((Views.ucDmTienTe)content).SetTitle();
            if (content is Views.ucDmTuyChon)
                ((Views.ucDmTuyChon)content).SetTitle();
            if (content is Views.ucNhomKhachHang)
                ((Views.ucNhomKhachHang)content).SetTitle();
            if (content is Views.ucNhomNguoiDung)
                ((Views.ucNhomNguoiDung)content).SetTitle();
            if (content is Views.ucSoDoPhong)
                ((Views.ucSoDoPhong)content).SetTitle();
            if (content is Views.ucTinNhan)
                ((Views.ucTinNhan)content).SetTitle();
        }
        */
        private void FrmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            SysLib.SysOptions.Save();
        }

        private void btnHelper_Click(object sender, RoutedEventArgs e)
        {
            string HelpPath = System.Windows.Forms.Application.StartupPath + "\\Help.chm";
            if (!System.IO.File.Exists(HelpPath))
            {
                MessageBox.Show(App.M_LAN.Equals("V") ? "Không tìm thấy file help.chm" : "help.chm file not found", "QLKS", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            System.Diagnostics.Process.Start("help.chm");
        }

        private void btnDmXe_Click(object sender, RoutedEventArgs e)
        {
            if (content.ToString() == "PTExpress.Views.ucDmXe")
                return;
            content = new ucDmXe();
            mainContent.Children.Clear();
            mainContent.Children.Add(content);
        }
    }
}
